$(function () {
    //文章类型 
    $.ajax({
        type: 'get',
        url: BigNew.index_category,
        success(backData) {
            if (backData.code == 200) {
                let resHtml = template('categoryTem', backData)
                $('.left_menu ').html(resHtml)
                $('.level_two ').html('<li class="up"></li>' + resHtml);

            };
        },
    });

    //最新评论
    $.ajax({
        type: 'get',
        url: BigNew.index_latest_comment,
        success(backData) {
            // console.log(backData);
            if (backData.code == 200) {
                let resHtml = template('commentTem', backData);
                $('.comment_list').html(resHtml)
            };
        },
    });

    //文章热门排行
    $.ajax({
        type: 'get',
        url: BigNew.index_rank,
        success(backData) {
            if (backData.code == 200) {
                for (let i = 0; i < backData.data.length; i++) {
                    $('.content_list li').eq(i).children('a').text(backData.data[i].title);
                    $('.content_list li').eq(i).children('a').attr('href', './article.html?id=' + backData.data[i].id);
                };
            };

        },
    });

    //焦点关注
    $.ajax({
        type: 'get',
        url: BigNew.index_attention,
        success(backData) {
            // console.log(backData);
            if (backData.code == 200) {
                for (let i = 0; i < backData.data.length; i++) {
                    $('.guanzhu_list li').eq(i).children('a').text(backData.data[i].intro);
                    $('.guanzhu_list li').eq(i).children('a').attr('href', './article.html?id=' + backData.data[i].id);
                }

            };
        },
    });
























    let value = window.location.search;
    //分类id
    let value1 = value.split('=')[0];
    //搜索的词语
    let value2 = value.split('=')[1];
    console.log(value1);
    console.log(value2);
    if (value == '') {
        window.location.href = './index.html';
    } else if (value1 == '?id') {
        console.log('分类进来的');

        $.ajax({
            type: 'get',
            url: BigNew.index_search,
            data: {
                type: value2
            },
            success(backData) {
                if (backData.code == 200) {
                    if (backData.data.data.length > 0) {
                        let resHtml = template('listTemp', backData.data);
                        $('.setfr').html('<div class="list_title"><h3>' + backData.data.data[0].category + '</h3></div>' + resHtml)
                    } else {
                        $('.setfr').html('<div class="list_title"><h3>没有数据</h3></div>')
                    }

                };
            },
        });

    } else {

        // 把搜索词转码
        value2 = decodeURI(value2)
        $.ajax({
            type: 'get',
            url: BigNew.index_search,
            data: {
                key: value2
            },
            success(backData) {
                if (backData.code == 200) {
                    console.log(backData);
                    if (backData.code == 200) {
                        if (backData.data.data.length > 0) {
                            let resHtml = template('listTemp', backData.data);
                            $('.setfr').html('<div class="list_title"><h3>搜索词：' + value2 + '</h3></div>' + resHtml)
                        } else {
                            $('.setfr').html('<div class="list_title"><h3>没有数据</h3></div>')
                        }
                    };
                };
            },



        });



    }







});